#include <iostream>
using namespace std;

struct Node{
    int data;
    Node *next;
};

struct LinkQueue{
    Node *front, *rear;
};

void Create(LinkQueue &Q)
{
    Q.front=Q.rear=NULL;
}

int IsEmpty(const LinkQueue& Q)
{
    if(Q.front==NULL && Q.rear==NULL) return 1;
    return 0;
}

void EnQueue(LinkQueue& Q, int x)
{
    Node *NewNode = new Node;
    NewNode->data = x;
    NewNode->next = NULL;

    if(IsEmpty(Q))
    {
        Q.front = Q.rear = NewNode;
    }
    else
    {
        Q.rear->next = NewNode;
        Q.rear = NewNode;
    }
}

void DeQueue(LinkQueue& Q, int& x)
{
    if(IsEmpty(Q))
    {
        cout<<"队空\n";
        return ;
    }

    Node *p = Q.front;
    x = p->data;
    if(Q.front == Q.rear)
    {
        Q.front = Q.rear = NULL;
    }
    else
    {
        Q.front = Q.front->next;
    }
    delete p;
}

void Display(const LinkQueue& Q)
{
    if(IsEmpty(Q))
    {
        cout<<"队空\n";
        return ;
    }
    Node *p = Q.front;
    while(p != NULL)
    {
        cout<<p->data<<"=>";
        p = p->next;
    }
    cout<<"NULL\n";
}


/**
 * @brief 删除倒数第n个节点
 * 
 * 
 */
Node* _removeEndNode(Node* preNode, Node* list, int n, int& index, bool& bflag)
{
    Node* rs = NULL;
    if (list->next != NULL)
    {
        rs = _removeEndNode(list, list->next, n, index, bflag);
        index++;
    }

    if (n == index)
    {
        Node* delNode = rs;
        list->next = rs->next;
        printf("delete :%d\n", delNode->data);
        delete delNode;
        delNode = nullptr;
        bflag = true;
    }
    else if (nullptr == preNode && !bflag && (index+1)==n)
    {
        Node* delNode = list;
        list = list->next;
        printf("delete :%d\n", delNode->data);
        delete delNode;
        delNode = nullptr;
    }
    
    return list;
}
Node* removeEndNode(Node* list, int n)
{
    int index = 0;
    bool bflag = false;
    return _removeEndNode(nullptr, list, n, index, bflag);
}

Node* CreateList()
{
    Node *list = NULL, *head;
    for (size_t i = 1; i < 11; i++)
    {
        Node* newNode = new Node;
        newNode->data = i;
        newNode->next = NULL;
        if (list == NULL)
        {
            list = newNode;
            head = list;
        }
        else
        {
            list->next = newNode;
            list = newNode;
        }
    }

    return head;
}

int main()
{
    auto displaylist = [](Node* list){
        Node* tmp = list;
        while (tmp != NULL)
        {
            printf("%d ", tmp->data);
            tmp = tmp->next;
        }
        printf("\n");
    };
    int n = 1;
    while (cin>>n)
    {
        Node* list = CreateList();
        displaylist(list);
        list = removeEndNode(list, n);
        displaylist(list);
    }
    
    
    // LinkQueue Q;
    // Create(Q);
    // EnQueue(Q,1);
    // EnQueue(Q,2);
    // EnQueue(Q,3);
    // cout<<"队列状况为 :";
    // Display(Q);
    
    // int x;
    // DeQueue(Q,x);
    // cout<<"乘客"<<x<<"出队乘车\n";
    // cout<<"队列状况为 :";
    // Display(Q);

    // EnQueue(Q,4);
    // DeQueue(Q,x);
    // cout<<"乘客"<<x<<"出队乘车\n";
    // cout<<"队列状况为 :";
    // Display(Q);
    return 0;
}